﻿using HandyControl.Controls;
using HandyControl.Data;
using ShanNiang.Mvvm.ViewModels;
using ShanNiang.Service.Attributes;
using ShanNiang.Service.Constants;
using System.IO;
using System.Media;
using System.Runtime.Versioning;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ShanNiang.Packing.UserControls
{
    /// <summary>
    /// LogoutControl.xaml 的交互逻辑
    /// </summary>
    [MenuControl(CommonData.MENU_LOGOUT, "退出", 100,CommonData.MENU_ICON_LOGOUT)]
    [SupportedOSPlatform("windows")]
    public partial class LogoutControl : UserControl
    {
        //private StringBuilder cache = new StringBuilder();
        //private ScanerListener _listener;

        public LogoutControl(LogoutViewModel logoutViewModel)
        {
            InitializeComponent();
            DataContext = logoutViewModel;
            //InputMethod.Current.ImeState = InputMethodState.Off;
            //_listener = new ScanerListener();
            //_listener.ScanerEvent += ScannerListener_ScanerEvent;
        }

        //private void ScannerListener_ScanerEvent(object? sender, ScanerEventArgs e)
        //{
        //    tb_ScannedText.Text = e.ScannedText;
        //}

        //private void UserControl_Loaded(object sender, RoutedEventArgs e)
        //{
        //    _listener.Start();

        //}

        //private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        //{
        //    _listener.Stop();
        //    //tb_ScannedText.Focus();
        //}

        private void tb_ScannedText_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter || e.Key == Key.Return)
            {
                HandyControl.Controls.MessageBox.Show(tb_ScannedText.Text);
                tb_ScannedText.Text = "";
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Task.Run(() => { Console.Beep(436 , 500);  Console.Beep(436 * 2, 1000); });
            var soundPath = Path.Combine(Environment.CurrentDirectory, "sounds/Scaned.wav");
            //SoundPlayer simpleSound = new SoundPlayer(soundPath);
            //Growl.Success(new GrowlInfo { ActionBeforeClose=(s)=> { HandyControl.Controls.  MessageBox.Show($"hellow {s}");return s; } });
            //simpleSound.Play();
            Growl.Success("Properties.Langs.Lang.GrowlInfo", "2");
            //SystemSounds.Beep.Play();
            //SystemSounds.Beep.Play();
            //SystemSounds.Hand.Play();

        }
    }

}
